﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>部门排序</title>
    @Html.Partial("LoadPanelPartial")
    @if (false)
    {
        <script src="../../../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>      
        <script src="../../../../Scripts/json2.js" type="text/javascript"></script>    
    }
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/json2.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Common/GetRootPath.ashx", true)" type="text/javascript"></script>

    @Html.DevExpress().GetStyleSheets(

        new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme }
)
    @Html.DevExpress().GetScripts(
        new Script { ExtensionType = ExtensionType.ListBox }
)

    <script type="text/javascript">
        $(function () {
            var json = $('#hidJson').val();
            if (json != "") {
                var dirList = JSON.parse(json);

                var objLbx = document.getElementById("idListBoxCatalog");
                objLbx.options.length = 0;
                var nDefaultSelIndex = -1;
                var focusedId = $('#hidFocusId').val();

                for (var i = 0; i < dirList.length; i++) {
                    var newOption = new Option(dirList[i]["FDeptName"], dirList[i]["FDeptNo"], false, false);
                    objLbx.options.add(newOption);
                    if (focusedId == dirList[i]["FDeptNo"]) {
                        nDefaultSelIndex = i;
                    }
                }

                objLbx.selectedIndex = nDefaultSelIndex;

            }

        });

        function MoveUp() {
            var objLbx = document.getElementById("idListBoxCatalog");
            var nSelIndex = objLbx.selectedIndex;

            if (nSelIndex <= 0) return;

            var selValue = objLbx.options[nSelIndex].value;
            var selText = objLbx.options[nSelIndex].text;

            objLbx.options[nSelIndex].value = objLbx.options[nSelIndex - 1].value;
            objLbx.options[nSelIndex].text = objLbx.options[nSelIndex - 1].text;

            objLbx.options[nSelIndex - 1].value = selValue;
            objLbx.options[nSelIndex - 1].text = selText;

            objLbx.selectedIndex = nSelIndex - 1;
        }

        function MoveDown() {
            var objLbx = document.getElementById("idListBoxCatalog");
            var nSelIndex = objLbx.selectedIndex;

            if (nSelIndex >= objLbx.options.length - 1) return;

            var selValue = objLbx.options[nSelIndex].value;
            var selText = objLbx.options[nSelIndex].text;

            objLbx.options[nSelIndex].value = objLbx.options[nSelIndex + 1].value;
            objLbx.options[nSelIndex].text = objLbx.options[nSelIndex + 1].text;

            objLbx.options[nSelIndex + 1].value = selValue;
            objLbx.options[nSelIndex + 1].text = selText;

            objLbx.selectedIndex = nSelIndex + 1;
        }

        function SaveResult() {
            lpModal.Show();
            var objLbx = document.getElementById("idListBoxCatalog");

            var dispSeq = "";
            var nOptionCount = objLbx.options.length;
            for (var i = 0; i < nOptionCount; i++) {
                dispSeq += objLbx.options[i].value;
                dispSeq += ",";
            }

            if (dispSeq == "") {
                alert("无排序的数据,不需要进行保存");
                lpModal.Hide();
            } else {
                $.ajax({
                    type: 'POST',
                    url: rootPath + '/Admin/Dept/SaveRearrange',
                    data: { deptNos: dispSeq },
                    success: function (result) {
                        var msg = result.split('|');
                        if (msg[0] == "SUCCESS") {
                            alert("保存成功");
                            window.returnValue = 'SUCCESS';
                            window.close();
                        }
                        else {
                            if (msg.length > 1) {
                                alert(msg[1]);
                            }
                        }
                    }
                });
            }

        }

    </script>

</head>
<body>
    <table border="0" cellpadding="1" cellspacing="1" width="100%" style="font-size: 9pt;">
        <tr>
            <td width="80%" valign="top">
                <select id="idListBoxCatalog" name="idListBoxCatalog" multiple="true" style="width: 100%; height: 350px;">
                </select>
            </td>
            <td width="20%">
                @Html.DevExpress().Button(settings =>
              {
                  settings.Name = "btnUp";
                  settings.Text = "上移";
                  settings.ControlStyle.CssClass = "button";
                  settings.ClientSideEvents.Click = "MoveUp";
                  settings.Images.Image.Url = Url.Content("~/Content/ControlImages/up.png");
              }).GetHtml()
                <br />
                @Html.DevExpress().Button(settings =>
              {
                  settings.Name = "btnDown";
                  settings.Text = "下移";
                  settings.ControlStyle.CssClass = "button";
                  settings.ClientSideEvents.Click = "MoveDown";
                  settings.Images.Image.Url = Url.Content("~/Content/ControlImages/down.png");
              }).GetHtml()
                <hr />
                @Html.DevExpress().Button(settings =>
              {
                  settings.Name = "btnSave";
                  settings.Text = "保存";
                  settings.ControlStyle.CssClass = "button";
                  settings.ClientSideEvents.Click = "SaveResult";
                  settings.Images.Image.Url = Url.Content("~/Content/ControlImages/filesave.png");
              }).GetHtml()
            </td>
        </tr>
    </table>
    @Html.Hidden("hidJson", ViewData["listJson"])
    @Html.Hidden("hidFocusId", ViewData["focusId"])
</body>
</html>
